USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Bills-Insert]    Script Date: [[20120714223925]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223925]]
-- Description:	Insert record into table [dbo].[Bills]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Bills-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Bills-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Bills-Insert]
	/*@Bill_RowNumber int =Null OUTPUT , 
	@Bill_ID uniqueidentifier =Null  , 
	@Bill_Code varchar(50) =Null  , 
	@BillType_ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Date datetime =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Bills](/*[Bill_ID], [Bill_Code], [BillType_ID], [Dealer_ID], [Date]*/)
	VALUES     (/*@Bill_ID, @Bill_Code, @BillType_ID, @Dealer_ID, @Date*/)

	/*SELECT @Bill_RowNumber = [Bill_RowNumber]
    FROM [dbo].[Bills]
    WHERE  ( [Bill_ID] =@Bill_ID )
	AND  ( [Bill_Code] =@Bill_Code )
	AND  ( [BillType_ID] =@BillType_ID )
	AND  ( [Dealer_ID] =@Dealer_ID )
	AND  ( [Date] =@Date )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Bills-update]    Script Date: [[20120714223925]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223925]]
-- Description:	Update record in table [dbo].[Bills]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Bills-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Bills-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Bills-update]
	/*@Bill_RowNumber int =Null OUTPUT , 
	@Bill_ID uniqueidentifier =Null  , 
	@Bill_Code varchar(50) =Null  , 
	@BillType_ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Date datetime =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Bills] SET 
		/*[Bill_ID] =@Bill_ID, 
		[Bill_Code] =@Bill_Code, 
		[BillType_ID] =@BillType_ID, 
		[Dealer_ID] =@Dealer_ID, 
		[Date] =@Date*/
		/*WHERE ([Bill_ID] = @Bill_ID)*/
	/**/

	/*SELECT @Bill_RowNumber = [Bill_RowNumber]
    FROM [dbo].[Bills]
	WHERE ([Bill_ID] = @Bill_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Bills-Insert-Update]    Script Date: [[20120714223925]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223925]]
-- Description:	Insert OR Update record into table [dbo].[Bills]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Bills-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Bills-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Bills-Insert-Update]
	/*@Bill_RowNumber int =Null OUTPUT , 
	@Bill_ID uniqueidentifier =Null  , 
	@Bill_Code varchar(50) =Null  , 
	@BillType_ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Date datetime =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Bills] 
					/*WHERE ([Bill_ID] = @Bill_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Bills](/*[Bill_ID], [Bill_Code], [BillType_ID], [Dealer_ID], [Date]*/)
		VALUES     (/*@Bill_ID, @Bill_Code, @BillType_ID, @Dealer_ID, @Date*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Bills] SET 
			/*[Bill_ID] =@Bill_ID, 
			[Bill_Code] =@Bill_Code, 
			[BillType_ID] =@BillType_ID, 
			[Dealer_ID] =@Dealer_ID, 
			[Date] =@Date*/
			/*WHERE ([Bill_ID] = @Bill_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Bill_RowNumber = [Bill_RowNumber]
    FROM [dbo].[Bills]
	WHERE ([Bill_ID] = @Bill_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Bills-Delete]    Script Date: [[20120714223925]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223925]]
-- Description:	delete records from table [dbo].[Bills] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Bills-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Bills-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Bills-Delete]
	/*@Bill_RowNumber int =null  , 
	@Bill_ID uniqueidentifier =null  , 
	@Bill_Code varchar(50) =null  , 
	@BillType_ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Date datetime =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Bills]
	WHERE /*( [Bill_RowNumber] = ISNULL(@Bill_RowNumber, [Bill_RowNumber]) )
	AND ( [Bill_ID] = ISNULL(@Bill_ID, [Bill_ID]) )
	AND ( [Bill_Code] like ISNULL(@Bill_Code, [Bill_Code]) )
	AND ( [BillType_ID] = ISNULL(@BillType_ID, [BillType_ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Date] = ISNULL(@Date, [Date]) )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Bills-Select]    Script Date: [[20120714223925]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223925]]
-- Description:	select records from table [dbo].[Bills] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Bills-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Bills-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Bills-Select]
	/*@Bill_RowNumber int =null  , 
	@Bill_ID uniqueidentifier =null  , 
	@Bill_Code varchar(50) =null  , 
	@BillType_ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Date datetime =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Bills]
	WHERE /*( [Bill_RowNumber] = ISNULL(@Bill_RowNumber, [Bill_RowNumber]) )
	AND ( [Bill_ID] = ISNULL(@Bill_ID, [Bill_ID]) )
	AND ( [Bill_Code] like ISNULL(@Bill_Code, [Bill_Code]) )
	AND ( [BillType_ID] = ISNULL(@BillType_ID, [BillType_ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Date] = ISNULL(@Date, [Date]) )*/
END
GO
-- =============================================
